home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / picture ƒ / animate.c next >
Text File  |  1990-11-08  |  2KB  |  87 lines

  1. /*
  2. *    FILE:        animate.c
  3. *    AUTHOR:        R. Gonzalez
  4. *    CREATED:    November 8, 1990
  5. *
  6. *    defines methods for animated nested segment
  7. */
  8.  
  9. # include    "animate.h"
  10. # include    "error.h"
  11. # include    <stdlib.h>
  12.  
  13. extern Error    *gerror;
  14.  
  15. /******************************************************************
  16. *    initialize - derived class must call this first when initing.
  17. *    Be sure to allocate and initialize an element of the array
  18. *    animation[] for each segment.  This element indicates how
  19. *    the respective segment is transformed when the nested segment
  20. *    is animated.  If any of the segments are themselves animated
  21. *    segments, then you must call:
  22. *        log_animated_segment(segment[i]);
  23. ******************************************************************/
  24. boolean    Animated_Segment::init(void)
  25. {
  26.     int        i;
  27.     
  28.     Nested_Segment::init();
  29.     
  30.     for (i=0 ; i<MAX_SEGMENTS ; i++)
  31.         animation[i] = NULL;
  32.     
  33.     num_animated_segments = 0;
  34.     
  35.     return TRUE;
  36. }
  37.  
  38. /******************************************************************
  39. *    animate - no need to override
  40. ******************************************************************/
  41. void    Animated_Segment::animate(void)
  42. {
  43.     int        i;
  44.     
  45.     for (i=0 ; i<num_animated_segments ; i++)
  46.         animated_segment_ptr[i]->animate();
  47.     
  48.     for (i=0 ; i<num_segments ; i++)
  49.     {
  50.         if (animation[i] == NULL)
  51.             gerror->report("Missing animation for this segment");
  52.         else
  53.             segment[i]->move(animation[i]);
  54.     }
  55. }
  56.  
  57. /******************************************************************
  58. *    Log a pointer to an animated segment in the array
  59. *    animated_segment_ptr[] and increment num_animated_segments.
  60. ******************************************************************/
  61. void    Animated_Segment::log_animated_segment(Segment* seg)
  62. {
  63.     animated_segment_ptr[num_animated_segments++] =
  64.         (Animated_Segment*) seg;
  65. }
  66.  
  67. /******************************************************************
  68. *    destroy - no need to override.
  69. ******************************************************************/
  70. boolean    Animated_Segment::destroy(void)
  71. {
  72.     int        i;
  73.     
  74.     for (i=0 ; i<num_segments ; i++)
  75.         if (animation[i] != NULL)
  76.         {
  77.             animation[i]->destroy();
  78.             delete(animation[i]);
  79.         }
  80.     
  81.     Nested_Segment::destroy();
  82.     
  83.     return TRUE;
  84. }
  85.  
  86.  
  87.